package com.example.mymatch.service.Imp;

import com.example.mymatch.dao.ICheckwork;
import com.example.mymatch.model.Checkwork;
import com.example.mymatch.service.ICheckworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对服务接口规范的方法实现
 * 编写者：杨滢
 */

@Service
public class ICheckworkServiceImpl implements ICheckworkService {

    @Autowired
    private ICheckwork checkworkMapper;

    @Override
    public int insertCheckwork(Checkwork checkwork){
        int checkworkValue=0;
        //查看当前用户名称不能重复
        Checkwork checkwork1=new Checkwork();
        checkwork1.setCheckName(checkwork.getCheckName());
        List<Checkwork> getC=checkworkMapper.getAllCheckwork(checkwork1);
        if (getC.size()>=1){
            //不可以添加用户名称
            checkworkValue=-1;
        }else {
            checkworkValue=checkworkMapper.insertCheckwork(checkwork);
        }
        return checkworkValue;
    }

    @Override
    public List<Checkwork> getAllCheckwork(Checkwork checkwork){
        return checkworkMapper.getAllCheckwork(checkwork);
    }

    @Override
    public int updateCheckwork(Checkwork checkwork){
        int checkworkValue=0;
        //判断主键不能为0
        if (checkwork.getId()!=0){
            //主键信息必修存在
            //名称不能重复
            checkworkValue=checkworkMapper.updateCheckwork(checkwork);
        }
        return checkworkValue;
    }

    @Override
    public  int deleteCheckwork(Checkwork checkwork){
        int checkworkValue=0;
        //判断主键不能为0
        if (checkwork.getId()!=0){
            //主键是否有其他表有关联，如果关联，则先删除其他表的信息，或者给出此条信息不允许被删除
            checkworkValue=checkworkMapper.deleteCheckwork(checkwork);
        }
        return checkworkValue;
    }

    //单条查询
    @Override
    public Checkwork getCheckwork(Checkwork checkwork){
        Checkwork checkwork1=new Checkwork();
        if (checkwork.getId()!=0){
            checkwork1=checkworkMapper.getCheckwork(checkwork);
        }
        return checkwork1;
    }
}
